
package com.thxrinfo.operate.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.thxrinfo.operate.api.entity.Merchant;
import com.thxrinfo.operate.api.vo.MerchantVO;
import com.thxrinfo.operate.mapper.MerchantMapper;
import com.thxrinfo.operate.service.MerchantService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * 商户表
 *
 * @author ct
 * @date 2023-03-06 15:07:48
 */
@Service
@RequiredArgsConstructor
public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> implements MerchantService {

	private static final PasswordEncoder ENCODER = new BCryptPasswordEncoder();

	private final MerchantMapper merchantMapper;


	@Override
	public IPage<MerchantVO> page(Page page, Merchant merchant) {
		return merchantMapper.page(page, merchant);
	}

	@Override
	public Boolean saveMerchant(Merchant merchant) {
		Merchant saveObj = new Merchant();
		BeanUtils.copyProperties(merchant, saveObj);
		saveObj.setPassword(ENCODER.encode(merchant.getPassword()));
		int result = baseMapper.insert(saveObj);
		return result == 0 ? Boolean.FALSE : Boolean.TRUE;
	}
}
